package ru.ipccenter.jshell.frontend.shell;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import ru.ipccenter.jshell.InterprocessStream;

public class ShellInternalImpl implements ShellInternal {

    InputStream  input;
    OutputStream output;
    OutputStream error;
    
    public ShellInternalImpl(InputStream input, OutputStream output, OutputStream error) {
        
        this.input  = input;
        this.output = output;
        this.error  = error;
    }
    
    @Override
    public InterprocessStream read() {
        
        return new InterprocessStreamInternalImpl(getInputSocketStream(), this); 
    }

    @Override
    public InterprocessStream read(String file) throws IOException {
        
        return new InterprocessStreamInternalImpl(new FileInputStream(file), this);
    }

    @Override
    public InterprocessStream exec(String... args) {
        
        InterprocessStreamInternal ips = 
            new InterprocessStreamInternalImpl(new ByteArrayInputStream(new byte[0]), this);
        return Executor.exec(ips, this, args, null, null);
    }

    @Override
    public void cd(String path)
    {
        // TODO Auto-generated method stub
        
    }

    @Override
    public void pwd()
    {
        // TODO Auto-generated method stub
        
    }

    @Override 
    public InputStream getInputSocketStream() {
        
        return input;
    }

    @Override
    public OutputStream getOutputSocketStream() {

        return output;
    }

    @Override
    public OutputStream getErrorSocketStream() {

        return error;
    }

}
